/**
 * 内容
 */
Ext.define('mtons.main.view.ContentView', {
	extend : 'Ext.tab.Panel',
	alias : 'widget.contentView',
	activeTab : 1,
	enableTabScroll : true,
	defaults : {
		autoScroll : true
	},
	addView : function(view) {
		var component = Ext.ComponentQuery.query(view.xtype, this);
		if (component.length > 0) {
			component = component[0]
		} else {
			component = this.add(view);
		}
		this.setActiveTab(component);
		return component;
	}
});

/**
 * 树
 */
Ext.define("mtons.main.view.TreeMenu", {
	extend : "Ext.tree.Panel",
	alias : "widget.treeMenu",
	rootVisible : false,
	initComponent : function() {
		if (this.dataProvider) {
			this.root = new Object();
			this.root.expanded = true;
			this.root.children = this.dataProvider;
		}
		this.callParent(arguments);
	}
});

/**
 * 菜单
 */
Ext.define('mtons.main.view.MenuView', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.menuView',
	split : true,
	border : false,
	width : 200,
	minSize : 175,
	maxSize : 400,
	collapsible : true,
	margins : '0 0 0 5',
	layout : 'accordion',
	initComponent : function() {

		if (this.dataProvider) {
			var length = this.dataProvider.length;
			this.items = new Array();
			for (var i = 0; i < length; i++) {
				var data = this.dataProvider[i];
				this.items.push({
					title : data.title,
					xtype : 'treeMenu',
					dataProvider : data.treeMenu
				});
			}
		}

		this.callParent(arguments);
	}
});

/**
 * 主视图
 */
Ext.define('mtons.main.view.MainView', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.mainView',
	layout : 'border',
	items : [ {
		id : 'topContent',
		collapisble : true,
		region : 'north',
		height : 0
	}, {
		id : 'contentView',
		region : 'center',
		xtype : 'contentView'
	}, {
		id : 'bottomContent',
		title : 'Mtons系统',
		layout : 'fit',
		region : 'south',
		collapisble : true
	} ],
	initMenu : function(data) {
		this.add({
			title : '菜单',
			id : 'menuView',
			region : 'west',
			dataProvider : data,
			xtype : 'menuView'
		});
	}
});